package cn.project.lemontree.controller;

import cn.project.lemontree.aop.SystemControllerLog;
import cn.project.lemontree.service.InsuranceService;
import cn.project.lemontree.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/insurance")
@Api(tags = "保险管理模块")
@CrossOrigin  //跨域访问
public class InsuranceController {
    @Resource
    private InsuranceService insuranceService;

    @ApiOperation("分页查询保险信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="页码",required=true,dataTypeClass = int.class,example = "1"),
            @ApiImplicitParam(name="size",value="每页行数",required=true,dataTypeClass = int.class,example = "10"),
            @ApiImplicitParam(name="ddesc",value="原因",required=false,dataTypeClass = String.class)
    })
    @GetMapping("/listpage")
    public CommonResult<Map<String ,Object>> listpage(int page,int size,String ddesc){
        Map<String ,Object> map = new HashMap<>();
        map.put("data" ,insuranceService.listpage(page,size,ddesc));
        map.put("count" ,insuranceService.count(ddesc));
        map.put("page" ,page);
        return CommonResult.success(map);
    }

    @SystemControllerLog(description = "删除保险")
    @ApiOperation("删除保险信息")
    @GetMapping("/remove")
    public CommonResult remove(@RequestParam("insurance_id") int insurance_id){
        return CommonResult.success(insuranceService.removeById(insurance_id));
    }
}
